/**
 * @author Vitor Franco do Carmo (vitor.carmo@cpmbraxis.com)
 * @since 07/08/2013
 *
 */
package br.com.vfcfw.test.functional.browser;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverServer;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
 * Classe responsável por rodar o Internet Explorer nos testes funcionais.
 * 
 * @author Vitor Franco do Carmo (vitor.carmo@cpmbraxis.com)
 * @since 07/08/2013
 * 
 */
public class InternetExplorerNavegador implements INavegador {

    private static InternetExplorerDriverServer server;

    private static WebDriver driver;

    /**
     * {@inheritDoc}
     * 
     * @see br.com.vfcfw.test.functional.browser.INavegador#inicializarServico()
     */
    @Override
    public void inicializarServico() {

        server = new InternetExplorerDriverServer(1);

        try {

            server.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * {@inheritDoc}
     * 
     * @see br.com.vfcfw.test.functional.browser.INavegador#finalizarServico()
     */
    @Override
    public void finalizarServico() {

        server.stop();
    }

    /**
     * {@inheritDoc}
     * 
     * @see br.com.vfcfw.test.functional.browser.INavegador#inicializarTeste()
     */
    @Override
    public void inicializarTeste() {

        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

        driver = new InternetExplorerDriver(ieCapabilities);
    }

    /**
     * {@inheritDoc}
     * 
     * @see br.com.vfcfw.test.functional.browser.INavegador#finalizarTeste()
     */
    @Override
    public void finalizarTeste() {

        driver.close();
    }

    /**
     * {@inheritDoc}
     * 
     * @see br.com.vfcfw.test.functional.browser.INavegador#obterDriver()
     */
    @Override
    public WebDriver obterDriver() {

        return driver;
    }

}
